package com.exthirteen.textgamescript.model.vo;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Data
@Slf4j
public class Result<T> {
    /**
     * 代码
     */
    private String code;
    /**
     * 结果
     */
    private String msg;
    /**
     * 数据
     */
    private T data;

    /**
     * 校验这个响应是否成功
     */
    public boolean isSuccess(){
        return ResultStatus.SUCCESS.getCode().equals(code);
    }

    public static <T> Result<T> success() {
        return response(ResultStatus.SUCCESS.getCode(), ResultStatus.SUCCESS.getMsg());
    }

    public static <T> Result<T> success(T data) {
        return response(ResultStatus.SUCCESS.getCode(), ResultStatus.SUCCESS.getMsg(), data);
    }

    public static <T> Result<T> error(String code, String msg) {
        return response(code, msg, null);
    }

    public static<T> Result<T> error(String code, String msg,T data) {
        return response(code, msg, data);
    }

    public static <T> Result<T> error(ResultStatus resultStatus) {
        return response(resultStatus.getCode(), resultStatus.getMsg(), null);
    }

    public static <T> Result<T> error(ResultStatus resultStatus, String msg) {
        return response(resultStatus.getCode(), msg, null);
    }

    public static <T> Result<T> response(String code, String msg, T data) {
        Result<T> response = new Result<>();
        response.setCode(code);
        response.setMsg(msg);
        response.setData(data);
        return response;
    }

    public static <T> Result<T> response(String code, String msg) {
        Result<T> response = new Result<>();
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }
}
